package sanrenxing.dayEnd.backRepertoryTotal.dao;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;
import sanrenxing.dayEnd.backRepertoryTotal.domain.CashRecAndPayStock;
import sanrenxing.dayEnd.backRepertoryTotal.domain.CashRecAndPayStockTwo;

import java.util.List;
import java.util.Map;

/**
 * 功能：现金应收应付库存的数据层接口类
 * 作者：赵思睿
 * 日期：2021/3/17 0017-11:14
 * 版本：1.0
 */
@Repository
public interface CashRecAndPayStockDao {
    /**
     * 将现金应收应付库存信息添加到数据库表中
     * @param crapStock 现金应收应付库存对象
     * @return 1：添加成功；0：添加失败
     */
    @Insert("insert into CashRecAndPayStock values(seqTaStock.nextval,#{caId},#{businType},#{fundId},to_date('${dates}','yyyy-MM-dd'),#{sumMoney},#{status},#{numbers})")
    public int add(CashRecAndPayStock crapStock);

    /**
     * 根据现金应收应付库存编号删除对象
     * @param crapId 现金应收应付库存编号
     * @return 1：删除成功；0：删除失败
     */
    @Delete("delete from CashRecAndPayStock where cashName=#{crapId}")
    public int delete(@Param("crapId") String crapId);

    /**
     * 分页查询所有现金应收应付库存信息
     * @param map 映射集合对象
     * @return 现金应收应付库存对象集合
     */
    @Select("<script>" +
            "select crap.cashName as crapId,ca.accName,crap.businType,f.fundName,crap.dates,crap.sumMoney,crap.status,crap.numbers from " +
            "((select rownum rn,CashRecAndPayStock.* from CashRecAndPayStock <where>#{end}>=rownum</where>) crap) " +
            " join fundSetup f on crap.fundId=f.fundId join cashAccount ca on crap.caId=ca.caId" +
            "<where>" +
            "<if test='crapStock.businType!=null'>" +
            " and businType=#{crapStock.businType}" +
            "</if>" +
            "<if test='crapStock.dates!=null'>" +
            " and to_char(dates,'yyyy-MM-dd')=#{crapStock.dates}" +
            "</if>" +
            " and rn>=#{start}" +
            "</where>" +
            "</script>")
    public List<CashRecAndPayStockTwo> selectAll(Map<String, Object> map);

    /**
     * 统计记录数
     * @return 记录数
     */
    @Select("select count(*) as counts from CashRecAndPayStock")
    public int count();
}
